package com.tc.filter;

import com.tc.entity.UserInfo;

import java.util.List;
import java.util.ListIterator;

/**
 * Created by cai.tian on 2017/5/10.
 */
public class IdFilter implements Filter {
   private long id;

    public void setId(long id) {
        this.id = id;
    }

    public long getId() {

        return id;
    }

    @Override
    public void doFilter(FilterChain chain) {
        List<UserInfo> userInfos = chain.getUserInfos();
        ListIterator<UserInfo> userInfoListIterator = userInfos.listIterator();
        if(userInfoListIterator!=null)
            while(userInfoListIterator.hasNext()){
                UserInfo next = userInfoListIterator.next();
                if (!(next.getId()!=id)) {
                    //aList.remove(str);   // 集合自身的remove()方法删除
                    userInfoListIterator.remove(); //迭代器的remove() 方法删除
                }
            }
    }
}
